﻿@using Novagoal.Website.Models.Views
@using Novagoal.Models
@using Novagoal.Website.WebApp.Helpers
@using Novagoal.Models.Utils
@using Novagoal.Utils
@using Ids.Web.Security;

@model IndexViewModel
@{
    ViewBag.Title = "Players | Index";
    Layout = "~/Views/Shared/ListLayout.cshtml";
}

@section Messages {
}

@section ListTitle {
    Player List
}

@section ListActions {
    @if (Model.List.HasFilters())
    {
        @Html.ActionLink("Show All", "Index", null, new { @class = "button ui-state-default ui-corner-all" } )
    }
    @if (Html.UserIsAtLeast(Enums.Roles.SuperUser))
    {
        @Html.ActionLink("New Player", "Add", null, new { @class = "button ui-state-default ui-corner-all" })
    }
}

@section ListContent {

    @Html.ValidationSummary(true)

    <table class="main-table">
        <tr>
            <th class="ui-widget-header ui-corner-all id">
                @ListHelper.SortAction(Url, Model.List, "Id", PlayerListSortField.Id) <br />
                @ListHelper.TextBoxFor(Model.List, PlayerListFilter.Id, "style=\"width:60px\"")
            </th>
            <th class="ui-widget-header ui-corner-all">
                @ListHelper.SortAction(Url, Model.List, "Name", PlayerListSortField.Name) <br />
                @ListHelper.TextBoxFor(Model.List, PlayerListFilter.Name)
            </th>
            <th class="ui-widget-header ui-corner-all">
                @ListHelper.SortAction(Url, Model.List, "Position", PlayerListSortField.Position) <br />
                @ListHelper.TextBoxFor(Model.List, PlayerListFilter.Position)
            </th>
            <th class="ui-widget-header ui-corner-all id">
                @ListHelper.SortAction(Url, Model.List, "MVP", PlayerListSortField.Mvp) <br />
                @ListHelper.TextBoxFor(Model.List, PlayerListFilter.Mvp, "style=\"width:60px\"")
            </th>
            <th class="ui-widget-header ui-corner-all date-time">
                @ListHelper.SortAction(Url, Model.List, "Created At", TeamListSortField.CreatedAt) <br />
            </th>
            <th class="ui-widget-header ui-corner-all date-time">
                @ListHelper.SortAction(Url, Model.List, "Updated At", TeamListSortField.UpdatedAt) <br />
            </th>
            <th class="ui-widget-header ui-corner-all actions">
                Actions
            </th>
        </tr>

        @for (int i = 0; i < Model.List.Items.Count; i++)
        {
            var player = Model.List.Items[i] as Player;
            <tr>
                <td class="center">
                    @player.Id
                </td>
                <td>
                    <span>@player.Name</span>
                </td>
                <td>
                    <span>@player.Position</span>
                </td>
                <td class="center">
                    @player.Mvp
                </td>
                <td>
                    @if (player.CreatedAt != null)
                    {
                        @Html.Encode(String.Format("{0:g}", player.CreatedAt.ToLocalTime()))
                    }
                </td>
                <td>
                    @if (player.UpdatedAt != null)
                    {
                        @Html.Encode(String.Format("{0:g}", player.UpdatedAt.ToLocalTime()))
                    }
                </td>
                <td class="center">
                    @Html.ActionLink("Edit", "Edit", new { id = player.Id }, new { @class = "button ui-state-default ui-corner-all" })
                </td>
            </tr>
        }

    </table>
}

@section ListPaging {
    @{
        @Html.DropDownListForPaging(4, 5, Model.RouteValues)
        string totalLabel = Model.List.TotalItems != 1 ? "players" : "player";
        @ListHelper.TotalItems(Model.List.TotalItems, totalLabel)
        @ListHelper.Paging(Url, Model.List)
    }
}

@section RecordEdition {
    
}


